package com.lanou.three;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
 * 定义一个Employee类,属性:name:String,age:int,salary:double
 * 把若干Employee对象放在List中,排序并遍历输出,排序规则:salary高的在前面,
 * salary相同时age大的在前面,age也相同时按照name升序排列
 *
 * @author zyj
 * @date 2022年05月24日 9:36
 */
public class Test {
    public static void main(String[] args) {
        List<Employee> list = new ArrayList<>();
        list.add(new Employee("Tom", 23, 5600));


        list.sort((o1, o2) -> {
            if (o1.getSalary() - o2.getSalary() > 0) {
                return -1;
            } else if (o1.getSalary() - o2.getSalary() < 0) {
                return 1;
            } else {
                if (o1.getAge() - o2.getAge() > 0) {
                    return -1;
                } else if (o1.getAge() - o2.getAge() < 0) {
                    return 1;
                } else {
                    if (o1.getName().compareTo(o2.getName()) > 0) {
                        return 1;
                    } else if (o1.getName().compareTo(o2.getName()) < 0) {
                        return -1;
                    } else {
                        return 0;
                    }
                }
            }
        });


    }
}

class Employee {
    private String name;
    private int age;
    private double salary;

    public Employee(String name, int age, double salary) {
        this.name = name;
        this.age = age;
        this.salary = salary;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public double getSalary() {
        return salary;
    }

    public void setSalary(double salary) {
        this.salary = salary;
    }

    @Override
    public String toString() {
        return "Employee{" +
                "name='" + name + '\'' +
                ", age=" + age +
                ", salary=" + salary +
                '}';
    }
}
